package org.pub.fast.jdbc.page;

public class OracleLimitSQLBuilder implements LimitSQLBuilder {
    public String build(String sql, int pageIndex, int pageSize) {
        StringBuffer pagingSelect = new StringBuffer(sql.length() + 100);
        pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
        pagingSelect.append(sql);
        pagingSelect.append(" ) row_ where rownum <= " + pageIndex * pageSize + ") where rownum_ > " + (pageIndex - 1) * pageSize);
        return pagingSelect.toString();
    }

    public static void main(String[] args) {
        OracleLimitSQLBuilder builder = new OracleLimitSQLBuilder();
        String s = builder.build("select * from tt where id=1", 2, 10);
        System.out.println(" " + s);
    }
}

